﻿using System.Windows;
using Project5188.BUS;
using Project5188.Client.ClientCodes;

namespace Project5188.Client
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class LoginWindow
    {
        private readonly bool _isTrial;

        public LoginWindow(bool isTrial)
        {
            InitializeComponent();

            _isTrial = isTrial;
        }

        private void BtnLoginClick(object sender, RoutedEventArgs e)
        {
            var users = new Users();
            var userList = users.LoginUser(txtUserName.Text, txtPass.Password);

            if (userList.Count > 0)
            {
                UserInfo.UserName = txtUserName.Text;
                UserInfo.RoleGroupId = userList[0].RoleGroupID;
                UserInfo.UserId = userList[0].ID;

                var main = new MainWindow(_isTrial);
                main.Show();
                Close();
            }
            else
            {
                MessageBox.Show("Kullanıcı adı veya şifresi hatalı!");
            }
        }

        private void BtnExitClick(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
